package kr.hkit.powerjava.alone;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class buttonFram extends JFrame implements ActionListener {

	private JPanel contentPane;
	private button CenterPanel;
	private LabelandTextPanel HeaderPanel;
	private text FooterPanel;
	private JButton btnNewButton;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					buttonFram frame = new buttonFram();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public buttonFram() {
		initialize();
	}
	private void initialize() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		HeaderPanel = new LabelandTextPanel((String) null);
		contentPane.add(HeaderPanel, BorderLayout.NORTH);
		
		CenterPanel = new button();
		contentPane.add(CenterPanel, BorderLayout.CENTER);

		
		btnNewButton = new JButton("변환2");
		CenterPanel.add(btnNewButton);
		btnNewButton.addActionListener(this);
		
		FooterPanel = new text();
		contentPane.add(FooterPanel, BorderLayout.SOUTH);
	}

	public LabelandTextPanel getPanel_1() {
		return HeaderPanel;
	}

	public void setPanel_1(LabelandTextPanel panel_1) {
		this.HeaderPanel = panel_1;
	}

	public text getPanel_2() {
		return FooterPanel;
	}

	public void setPanel_2(text panel_2) {
		this.FooterPanel = panel_2;
	}
	
	

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("변환2")) {
			int mile = 0;
			try {
				mile = Integer.parseInt(getPanel_1().getTextField().trim());
				
			} catch (NumberFormatException err) {
				JOptionPane.showMessageDialog(this, "숫자만 가능");
				getPanel_1().setTextField("");
			}
			getPanel_2().setTextField(mile + " 마일은 " + (mile * 1.6) + " 킬로미터입니다."+"");

			
		}
		
	}
}
